<div class="container-fluid">
  <h1>{{ database }}</h1>
  {% if comment is not empty %}
    <p>{{ t('Database comment:') }} <em>{{ comment }}</em></p>
  {% endif %}

  <p class="d-print-none">
    <button type="button" class="btn btn-secondary jsPrintButton">{{ get_icon('b_print', t('Print'), true) }}</button>
  </p>

  <div>
    {% for table in tables %}
      <div>
        <h2>{{ table.name }}</h2>
        {% if table.comment is not empty %}
          <p>{{ t('Table comments:') }} <em>{{ table.comment }}</em></p>
        {% endif %}

        <table class="table table-striped align-middle">
          <thead>
            <tr>
              <th>{{ t('Column') }}</th>
              <th>{{ t('Type') }}</th>
              <th>{{ t('Null') }}</th>
              <th>{{ t('Default') }}</th>
              {% if table.has_relation %}
                <th>{{ t('Links to') }}</th>
              {% endif %}
              <th>{{ t('Comments') }}</th>
              {% if table.has_mime %}
                <th>{{ t('Media type') }}</th>
              {% endif %}
            </tr>
          </thead>
          <tbody>
            {% for column in table.columns %}
              <tr>
                <td class="text-nowrap">
                  {{ column.name }}
                  {% if column.has_primary_key %}
                    <em>({{ t('Primary') }})</em>
                  {% endif %}
                </td>
                <td lang="en" dir="ltr"{{ 'set' != column.type and 'enum' != column.type ? ' class="text-nowrap"' }}>
                  {{ column.print_type }}
                </td>
                <td>{{ column.is_nullable ? t('Yes') : t('No') }}</td>
                <td class="text-nowrap">
                  {% if column.default is null and column.is_nullable %}
                    <em>NULL</em>
                  {% else %}
                    {{ column.default }}
                  {% endif %}
                </td>
                {% if table.has_relation %}
                  <td>{{ column.relation }}</td>
                {% endif %}
                <td>{{ column.comment }}</td>
                {% if table.has_mime %}
                  <td>{{ column.mime }}</td>
                {% endif %}
              </tr>
            {% endfor %}
          </tbody>
        </table>

        {% if table.indexes is not empty %}
          <h3>{{ t('Indexes') }}</h3>

          <table class="table table-striped align-middle">
            <thead>
              <tr>
                <th>{{ t('Keyname') }}</th>
                <th>{{ t('Type') }}</th>
                <th>{{ t('Unique') }}</th>
                <th>{{ t('Packed') }}</th>
                <th>{{ t('Column') }}</th>
                <th>{{ t('Cardinality') }}</th>
                <th>{{ t('Collation') }}</th>
                <th>{{ t('Null') }}</th>
                <th>{{ t('Comment') }}</th>
              </tr>
            </thead>

            <tbody>
              {% for index in table.indexes %}
                {% set columns_count = index.getColumnCount() %}
                <tr>
                <td rowspan="{{ columns_count }}">{{ index.getName() }}</td>
                <td rowspan="{{ columns_count }}">{{ index.getType()|default(index.getChoice()) }}</td>
                <td rowspan="{{ columns_count }}">{{ index.isUnique() ? t('Yes') : t('No') }}</td>
                <td rowspan="{{ columns_count }}">{{ index.isPacked()|raw }}</td>

                {% for column in index.getColumns() %}
                  {% if column.getSeqInIndex() > 1 %}
                    <tr>
                  {% endif %}
                  <td>
                    {{ column.getName() }}
                    {% if column.getSubPart() is not empty %}
                      ({{ column.getSubPart() }})
                    {% endif %}
                  </td>
                  <td>{{ column.getCardinality() }}</td>
                  <td>{{ column.getCollation() }}</td>
                  <td>{{ column.getNull() }}</td>

                  {% if column.getSeqInIndex() == 1 %}
                    <td rowspan="{{ columns_count }}">{{ index.getComments() }}</td>
                  {% endif %}
                  </tr>
                {% endfor %}
              {% endfor %}
            </tbody>
          </table>
        {% else %}
          <p>{{ t('No index defined!') }}</p>
        {% endif %}
      </div>
    {% endfor %}
  </div>

  <p class="d-print-none">
    <button type="button" class="btn btn-secondary jsPrintButton">{{ get_icon('b_print', t('Print'), true) }}</button>
  </p>
</div>
